<%
win_w = 35    # 小窓の幅
win_h = 30    # 小窓の高さ
win_hs = 20   # 小さい小窓の高さ

box_w = 300
box_h = win_hs*3+win_h*@month_pack[:count_issues]+win_hs*@month_pack[:count_prjs]+20
if @month_pack[:other]!=0 then
  box_h += win_hs
end
%>

<table width="100%" style="border:0;border-collapse:collapse;">
<tr>
  <!-- ************************************************ 左側を表示 -->
  <td style="width:<%=box_w%>px;padding:0px;">
    <div style="background: #ccc;">
    <div style="position:relative;height:<%=box_h%>px;overflow:auto;">

      <div style="position:absolute;top:1px;left:2px;">
      <div style="background: #eee;font-size:2.0em;">
      <div style="text-align:center;position:relative;top:1px;left:1px;width:<%=box_w-4%>px;height:<%=win_hs*2-2%>px;">
        <%= @this_year %>/<%= @month_names[@this_month-1] %>
      </div>
      </div>
      <div style="text-align:right;position:absolute;top:1px;left:1px;width:<%=box_w-4%>px;height:<%=win_hs*2-2%>px;">
        <%= link_to(">>", @link_params.merge(:day=>@next_month.day, :month=>@next_month.month, :year=>@next_month.year))%>
      </div>
      <div style="text-align:left;position:absolute;top:1px;left:1px;">
        <%= link_to("<<", @link_params.merge(:day=>@last_month.day, :month=>@last_month.month, :year=>@last_month.year))%>
      </div>
      </div>
<%
ofst_t = win_hs*3-5

@month_pack[:odr_prjs].each do |prj_pack|
  next if prj_pack[:count_issues] == 0
  prj = prj_pack[:prj]
  dsp_pos = prj_pack[:odr]
  prj_ofst_t = ofst_t

  ofst_t += win_hs
  prj_pack[:odr_issues].each do |issue_pack|
    next if issue_pack[:count_hours] == 0
    issue = issue_pack[:issue]
    issue_id = issue.nil? ? -1 : issue.id
    issue_odr = issue_pack[:odr]
    if issue.nil? || !issue.visible? then
      issueHtml = "<del>Issue:"+issue_id.to_s+"</del>"
    else
      issueHtml = issue.closed? ? "<del>"+issue.to_s+"</del>" : issue.to_s
    end
%>
    <div style="position:absolute;top:<%=ofst_t%>px;left:2px;">
      <div style="background: #eee;font-size:0.8em;">
        <div style="position:relative;top:1px;left:1px;width:<%=box_w-4%>px;height:<%=win_h-2%>px;">
          <%if !issue.nil? then%>
            <%if @this_uid==@crnt_uid then%>
              <a href="JavaScript:ticket_pos('<%=url_for(@link_params) %>',<%=issue_id%>,<%=issue_odr%>,<%=@issue_odr_max+((issue_odr.to_i<0)?1:0)%>);">
                <%= (issue_odr.to_i<0) ? "*" : issue_odr %>
              </a>
            <%end%>
            <%= link_to(issueHtml, {:controller=>"issues", :action=>"show", :id=>issue_id}, :popup=>true) %>
            <%= print_issue_cost(issue) %>
          <%end%>
          <div style="position:absolute;top:15px;right:15px;">
            <%=sprintf("%1.1f", issue_pack[:total])%>
          </div>
        </div>
      </div>
    </div>
<%
  ofst_t += win_h
 end
%>
  <div style="position:absolute;top:<%=prj_ofst_t%>px;left:2px;">
    <div style="background:#000;color:#fff;font-size:1.0em;">
      <div style="position:relative;top:1px;left:1px;width:<%=box_w-4%>px;height:<%=win_hs-2%>px;">
<%if @this_uid==@crnt_uid then%>
        <a href="JavaScript:prj_pos('<%=url_for(@link_params) %>',<%=prj.id%>,<%=dsp_pos%>,<%=@prj_odr_max+((dsp_pos.to_i<0)?1:0)%>);">
          <%= (dsp_pos.to_i<0) ? "*" : dsp_pos %>
        </a>
<%end%>
        <%= prj.name%>
          <div style="position:absolute;top:1px;right:10px;">
            <%=sprintf("%1.1f",prj_pack[:total])%>
          </div>
      </div>
    </div>
  </div>
<%
end
%>
    <%if @month_pack[:other]!=0 then%>
      <div style="position:absolute;top:<%=ofst_t%>px;left:2px;">
        <div style="background:#000;color:#fff;font-size:1.0em;">
          <div style="position:relative;top:1px;left:1px;width:<%=box_w-4%>px;height:<%=win_hs-2%>px;">
            private
              <div style="position:absolute;top:1px;right:10px;">
                <%=sprintf("%1.1f", @month_pack[:other])%>
              </div>
          </div>
        </div>
      </div>
    <%end%>
      <div style="position:absolute;bottom:10px;right:10px;">
        <%=sprintf("%1.1f", @month_pack[:total])%>
      </div>
      <div style="position:absolute;top:<%=win_hs*2%>px;right:10px;">
        <%=sprintf("%1.1f", @month_pack[:total])%>
      </div>
    </div>

    </div>
  </td>

  <!-- ************************************************ 右側を表示 -->
  <td>
    <div style="background: #ccc;">
    <div style="position:relative;height:<%=box_h%>px;overflow:auto;" id="day_scroll">

<% # チケット毎の合計時間を計算＆表示
(@first_date..@last_date).each do |date|
  day = date.day
  wday = date.wday
  ofst_l = win_w*(day-1)
  holidayEntry = WtHolidays.find(:all, 
                  :conditions=>["holiday=:h and deleted_on is null",{:h=>date}])
  if holidayEntry.size == 0 then
    bcolor = @wday_color[wday]
  else
    bcolor = "#fbc"
  end
  if day==@this_day then
    bcolor_day = "#cfc"
    today_id = 'id="day_scroll_today"'
  else
    bcolor_day = bcolor
    today_id = ''
  end
%>
    <div style="position:absolute;top:1px;left:<%=ofst_l%>px;" <%=today_id%> >
      <div style="background:<%=bcolor_day%>;">
        <div style="text-align:center;position:relative;top:1px;left:1px;width:<%=win_w-2%>px;height:<%=win_hs-2%>px;">
          <%= link_to(day, @link_params.merge(:day=>day)) %>
        </div>
      </div>
    </div>
    <div style="position:absolute;top:<%=win_hs+1%>px;left:<%=ofst_l%>px;">
      <div style="background:<%=bcolor%>;">
        <div style="text-align:center;position:relative;top:1px;left:1px;width:<%=win_w-2%>px;height:<%=win_hs-2%>px;">
          <%= @wday_name[wday]%>
        </div>
      </div>
    </div>
<%
ofst_t = win_hs*3-5
day_cost = 0

@month_pack[:odr_prjs].each do |prj_pack|
  next if prj_pack[:count_issues] == 0
  dsp_prj = prj_pack[:prj].id
  dsp_pos = prj_pack[:odr]
  prj_ofst_t = ofst_t

  ofst_t += win_hs
  prj_pack[:odr_issues].each do |issue_pack|
    next if issue_pack[:count_hours] == 0
    issue = issue_pack[:issue]
    issue_id = issue.nil? ? -1 : issue.id
    issue_odr = issue_pack[:odr]
%>
    <div style="position:absolute;top:<%=ofst_t%>px;left:<%=ofst_l%>px;">
      <div style="background:<%=bcolor%>;font-size:0.8em;">
        <div style="text-align:center;position:relative;top:5px;left:1px;width:<%=win_w-2%>px;height:<%=win_h-2%>px;">
<%
  if issue_pack[:total_by_day].has_key?(date) then
%>
          <%=sprintf("%1.1f", issue_pack[:total_by_day][date])%>
<%
   end
%>
        </div>
      </div>
    </div>
<%
  ofst_t += win_h
 end
%>
  <div style="position:absolute;top:<%=prj_ofst_t%>px;left:<%=ofst_l%>px;">
    <div style="background:#000;color:#fff;font-size:0.8em;">
      <div style="text-align:center;position:relative;top:5px;left:1px;width:<%=win_w-2%>px;height:<%=win_hs-2%>px;">
<%if prj_pack[:total_by_day].has_key?(date) then%>
        <%=sprintf("%1.1f", prj_pack[:total_by_day][date])%>
<%end%>
      </div>
    </div>
  </div>

<%
end
%>
<!--日毎の合計時間表示-->
    <div style="position:absolute;top:<%=win_hs*2%>px;left:<%=ofst_l%>px;">
      <div style="font-size:0.8em;">
        <div style="text-align:center;position:relative;top:1px;left:1px;width:<%=win_w-2%>px;height:<%=win_hs-2%>px;">
<%if @month_pack[:total_by_day].has_key?(date) then%>
          <%= sprintf("%1.1f", @month_pack[:total_by_day][date])%>
<%end%>
        </div>
      </div>
    </div>
<!--otherの時間表示-->
<%if @month_pack[:other]!=0 then%>
  <div style="position:absolute;top:<%=ofst_t%>px;left:<%=ofst_l%>px;">
    <div style="background:#000;color:#fff;font-size:0.8em;">
      <div style="text-align:center;position:relative;top:5px;left:1px;width:<%=win_w-2%>px;height:<%=win_hs-2%>px;">
<%if @month_pack[:other_by_day].has_key?(date) then%>
          <%= sprintf("%1.1f", @month_pack[:other_by_day][date])%>
<%end%>
      </div>
    </div>
  </div>
<%end%>

<%end%>
    </div>
    </div>
  </td>
</tr>
</table>

<script type="text/javascript">
<!--
  var scr = document.getElementById("day_scroll");
  var tgt = document.getElementById("day_scroll_today");
  scr.scrollLeft = tgt.offsetLeft - scr.offsetLeft;
-->
</script>
